package com.iot.processor.model;



import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 传感器数据模型
 * 用于存储解析后的IoT设备数据
 */
@Data
public class SensorData {
    
    @JsonProperty("deviceId")
    private String deviceId;
    
    @JsonProperty("timestamp")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime timestamp;
    
    @JsonProperty("temperature")
    private Double temperature;
    
    @JsonProperty("humidity")
    private Double humidity;
    
    @JsonProperty("rawMessage")
    private String rawMessage;
    
    public SensorData() {
    }
    
    public SensorData(String deviceId, LocalDateTime timestamp, Double temperature, Double humidity, String rawMessage) {
        this.deviceId = deviceId;
        this.timestamp = timestamp;
        this.temperature = temperature;
        this.humidity = humidity;
        this.rawMessage = rawMessage;
    }
    
    public String getDeviceId() {
        return deviceId;
    }
    
    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }
    
    public LocalDateTime getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(LocalDateTime timestamp) {
        this.timestamp = timestamp;
    }
    
    public Double getTemperature() {
        return temperature;
    }
    
    public void setTemperature(Double temperature) {
        this.temperature = temperature;
    }
    
    public Double getHumidity() {
        return humidity;
    }
    
    public void setHumidity(Double humidity) {
        this.humidity = humidity;
    }
    
    public String getRawMessage() {
        return rawMessage;
    }
    
    public void setRawMessage(String rawMessage) {
        this.rawMessage = rawMessage;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SensorData that = (SensorData) o;
        return Objects.equals(deviceId, that.deviceId) &&
               Objects.equals(timestamp, that.timestamp) &&
               Objects.equals(temperature, that.temperature) &&
               Objects.equals(humidity, that.humidity);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(deviceId, timestamp, temperature, humidity);
    }
    
    @Override
    public String toString() {
        return "SensorData{" +
                "deviceId='" + deviceId + '\'' +
                ", timestamp=" + timestamp +
                ", temperature=" + temperature +
                ", humidity=" + humidity +
                ", rawMessage='" + rawMessage + '\'' +
                '}';
    }
}